package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCategoryMapper;
import com.qf.pojo.DtsCategory;
import com.qf.service.DtsCategoryService;
import com.qf.vo.CategorySellAmts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/22 16:30
 */
@Service
public class DtsCategoryServiceImpl  implements DtsCategoryService {

    @Autowired
    private DtsCategoryMapper dtsCategoryMapper;

    @Override
    public List<CategorySellAmts> findGoodsCategoryAndTotal() {
        return dtsCategoryMapper.findGoodsCategoryAndTotal();
    }

    /**
     * 商品类目查看
     * @param id
     * @param name
     * @param sort
     * @param order
     * @param page
     * @param limit
     * @return
     */
    @Override
    public IPage<DtsCategory> findListByQuery(Integer id, String name, String sort, String order, Integer page, Integer limit) {
        return dtsCategoryMapper.selectPage(new Page(page,limit)
                ,new QueryWrapper<DtsCategory>()
                        .eq(!StringUtils.isEmpty(id),"id",id)
                        .like(!StringUtils.isEmpty(name),"name",name)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort));
    }

    /**
     * 商品类目添加
     * @param dtsCategory
     * @return
     */
    @Override
    public DtsCategory create(DtsCategory dtsCategory) {
        dtsCategoryMapper.insert(dtsCategory);
        return dtsCategory;
    }

    @Override
    public List<DtsCategory> findCategoryByPid(Integer pid) {
        return dtsCategoryMapper.selectList(new QueryWrapper<DtsCategory>().eq("pid",pid));
    }

    /**
     * 商品类目更新
     * @param dtsCategory
     * @return
     */
    @Override
    public DtsCategory update(DtsCategory dtsCategory) {
        dtsCategoryMapper.updateById(dtsCategory);
        return dtsCategory;
    }

    /**
     * 商品类目删除
     * @param dtsCategory
     * @return
     */
    @Override
    public DtsCategory delete(DtsCategory dtsCategory) {
        dtsCategoryMapper.deleteById(dtsCategory);
        return dtsCategory;
    }
}
